package com.xoa.service.url;

import com.xoa.dao.common.SysParaMapper;
import com.xoa.model.common.SysPara;
import com.xoa.util.ToJson;
import com.xoa.util.common.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

/**
 * @author zch
 * @date 2018/7/20 16:20
 * @desc
 */
@Service
public class MainstrBackUrlService {

    @Resource
    SysParaMapper sysParaMapper;

    public ToJson mainstrBackUrl(HttpServletRequest request){
        SysPara sysPara = new SysPara();
        ToJson json = new ToJson();
        sysPara= sysParaMapper.selectWebAddress();
        HttpServletRequest httpRequest=(HttpServletRequest)request;
//        String strBackUrl = "http://" + request.getServerName() + ":" + request.getServerPort() + httpRequest.getContextPath()
//                + httpRequest.getServletPath() + "?" + (httpRequest.getQueryString());
        String strBackUrl ="http://" +request.getServerName() + ":" + request.getServerPort();
        //   strBackUrls  数据库中的值 为空也是空  0
        String strBackUrls = sysPara.getParaValue();
        if (!StringUtils.checkNull(strBackUrls)){
            strBackUrl = strBackUrls;
            json.setFlag(0);
            json.setMsg("true");
            json.setTurn(true);
            json.setObj1(strBackUrls);
            json.setObject(strBackUrl);
        }else {
            json.setFlag(0);
            json.setMsg("true");
            json.setTurn(true);
            json.setObj1(strBackUrls);
            json.setObject(strBackUrl);
        }
        return json;
    }
}
